' (c) 2001 dr.-evil@mad.scientist.com. All rights reserved.
' You may use this control in your applications free of charge,
' provided that you do not redistribute this source code without
' giving me credit for my work. Of course, credit in your
' applications is always welcome.
Public Event Click()
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MyState As BtnState
Dim LastState As BtnState
Dim MouseIsDown As Boolean
Dim IsKeyDown As Boolean
Dim s_Enabled As Boolean
Dim s_Caption As String
Dim s_Font As Font
Public Property Get Caption() As String
Caption = s_Caption
End Property
Public Property Get Enabled() As Boolean
Enabled = s_Enabled
End Property
Public Property Get Font() As Font
Set Font = s_Font
End Property
Public Property Let Caption(Val As String)
s_Caption = Val
StandardButton.Caption = Val
Draw True ' force a redraw so the that the new caption is shown.
End Property
Public Property Let Enabled(Val As Boolean)
s_Enabled = Val
If Not Val Then
MyState = Disabled
UserControl.Enabled = False
ElseIf Val And (UserControl.Ambient.DisplayAsDefault) Then
MyState = Defaulted
UserControl.Enabled = True
Else
MyState = Normal
UserControl.Enabled = True
End If
Draw
StandardButton.Enabled = Val
End Property
Public Property Set Font(Val As Font)
Set s_Font = Val
Set UserControl.Font = Val
Set StandardButton.Font = Val
Draw
End Property
Private Sub StandardButton_Click()
RaiseEvent Click
End Sub
Private Sub StandardButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub
Private Sub StandardButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub
Private Sub StandardButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub
Private Sub Timer1_Timer() ' this provides for a MouseOut event.
If Not MouseIsDown Then
Dim Mouse As POINT_API
GetCursorPos Mouse
ScreenToClient hWnd, Mouse
If (Mouse.X < UserControl.ScaleLeft) Or (Mouse.Y < UserControl.ScaleTop) Or (Mouse.X > (UserControl.ScaleLeft + UserControl.ScaleWidth)) Or Mouse.Y > ((UserControl.ScaleTop + UserControl.ScaleHeight)) Then
Timer1.Enabled = False
If UserControl.Ambient.DisplayAsDefault Then
MyState = Defaulted
Else
MyState = Normal
End If
Draw
End If
End If
End Sub
Private Sub UserControl_AccessKeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If s_Enabled Then
RaiseEvent Click
Else
Beep
End If
End If
End Sub
Private Sub UserControl_AmbientChanged(PropertyName As String)
If Not ThemesSupported Then ' this event usually happens when another control on the form gets focus.